/**
 * Copyright (c) 2007,中企动力华南研发中心
 * All rights reserved.
 */
package com.ce.pms.house.web;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.UpLoadFile;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.exception.UILayerException;
import com.ce.pms.house.service.ICoWorkerService;
import com.ce.pms.house.service.IProjectService;
import com.ce.pms.house.vo.CoWorkerVO;
import com.ce.pms.house.vo.EnvironmentVO;
import com.ce.pms.house.vo.ImageVO;
import com.ce.pms.house.vo.LayoutVO;
import com.ce.pms.house.vo.ProjectVO;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.annotation.Scope;
import com.sitechasia.webx.core.support.Page;
/**
 * 功能描述：
 * @author 易贤建 创建日期：2008-7-8
 */
public class ProjectAction extends PmsBaseAction{
	private IProjectService projectService = null;
	private ICoWorkerService coWorkerService = null;
	private final String AREAID = "areaId";  //楼盘ID  不确定在那里会用到，先缓存下来。
	public static final String PROJECTVO = "projectVO"; //期数缓存KEY

	private final String DEVELOPER = "developer";  //标识开发商
	private final String DESIGN = "design";     //标识设计单位
	private final String CONSTRUCTION = "construction";     //标识设计单位
	private final String SUPERVISION = "supervision";     //标识设计单位

   /**
   * Function:期数列表页面
   * @param
   * @return
   * Create author:yixianjian
   * Create on:2008-6-26
   * Edit author:
   * Edit on:
   * Why:
    */
   public String initProjectList(@Read ProjectVO projectVO,
		   						 @Read(key="ec_p", defaultValue="1") int pageNo,
		   						 @Read(key="ec_crd",defaultValue="5")int pageSize){
	   checkNull(projectVO);
	   checkNull(projectVO.getAreaId());
	   setAttribute("areaId", projectVO.getAreaId());
	   Page page = projectService.queryProjects(projectVO, pageNo, pageSize);
	   setAttribute("projectList", page.getResult());
	   setAttribute("totalRows", Integer.valueOf(Long.valueOf(page.getTotalCount()).toString()));
	   setAttribute(AREAID,projectVO.getAreaId(), Scope.SESSION);
	   return "projectList";
   }
	/**
	* Function:期数添加主页面
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-8
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initProjectAdd(){
		removeObjectFSession();
		removeAttribute("isArea", Scope.SESSION);
		return "projectAddMain";
	}

	/**
	 * 功能描述:  期数修改页面<br>
	 * @param projectId
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initPorjectEdit(@Read(key="porjectId")Long projectId){
		checkNull(projectId);
		ProjectVO projectvo = projectService.findProjectById(projectId);
		setObject2Session(projectvo);
		setAttribute("is_Project_Edit", "is_Project_Edit");

		removeAttribute("isArea", Scope.SESSION);
		return "projectAddMain";
	}
	/**
	* Function:初始化基本信息页面
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-8
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initProjectBaseInfo(){
		return "projectBaseInfo";
	}

	/**
	* Function:初始化新增配套设施列表.列表从session缓存中获取
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initProjectEnvironmentList(){
		List EnvironmentSet = getObjectFSession().getEnvironmentVO();
		int environmentCount = EnvironmentSet == null? 0:EnvironmentSet.size();
		setAttribute("totalRows",Integer.valueOf(environmentCount));
		return "projectEnvironmentList";
	}
	/**
	* Function:初始化配套设施添加页面
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initProjectEnvironmentAdd(@Read(key="keyword")Long keyword){

		return "projectEnvironmentAdd";
	}
	/**初始化配套设施修改页面
	* Function:
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initProjectEnvironmentEdit(@Read(key="environmentId")Long id){
		checkNull(id);
		EnvironmentVO environmentVO = getEnvironmentVOFromSession(id);
		setAttribute("environmentVO", environmentVO);
		return "projectEnvironmentEdit";
	}

	/**
	 * 功能描述:  初始化建设规划页面。新增、修改全用一个页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initProjectLayoutAdd(){
		return "projectLayout";
	}

	/**
	 * 功能描述:  初始化参建单位主页<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initProjectJoinCorpMain(){
		return "projectJoinCorpMain";
	}

	/**
	 * 功能描述: 初始化参建单位已选择列表 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initCoWorkerSelectedList(@Read(key="coWorkerType")
										   @Out(key="coWorkerType")
										   String coworkerType){
		checkNull(coworkerType);
		Map map = getCoWorkerMapFromProject(coworkerType);
		int size = map == null ? 0 : map.size();
		setAttribute("totalRows", Integer.valueOf(size));
		return "coWorkerSelectedList";
	}

	/**
	 * 功能描述: 根据不同的参见单位类型初始化参见单位选择列表 <br>
	 * @param coworkerType
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initCoWorkerUnSelected(@Read(key="coWorkerType") @Out(key="coWorkerType") String coworkerType,
										 @Read(key="ec_p",defaultValue="1")int pageNo,
										 @Read(key="ec_crd",defaultValue="3")int pageSize){
		CoWorkerVO queryCondition =  getCoWorkerByType(coworkerType);
		queryCondition.setCoWorkerIDs(getCoWorkerIdsFromSession(coworkerType));
		queryCondition.setIsIn(false);
		Page page = coWorkerService.queryCoWorker(queryCondition, pageNo, pageSize);
		setAttribute("totalRows", Integer.valueOf(Long.valueOf(page.getTotalCount()).toString()));
		setAttribute("coworkList", page.getResult());
		return "coWorkerUnSelectedList";
	}

	/**
	* Function:添加期数基本资料
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-8
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String addBase(@Read ProjectVO projectvo){
		projectvo.setProjectCreator(super.getUserId());
		ProjectVO projectVO = projectService.addBase(projectvo);
		setObject2Session(projectVO);
		setAttribute();//设置关闭或者保存标识
		return "projectBaseInfo";
	}

	/**
	* Function:添加配套设施.
	* 在数据库中添加条记录后，需要同步缓存中的数据。
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String addEnvironment() {
		UpLoadFile upload=new UpLoadFile();
		EnvironmentVO environmentvo = new EnvironmentVO();
		List<ImageVO> imagelist = null;
		try {
			//获取图片列表
			imagelist = upload.parseFormAndUpload(getRequest(), environmentvo);
			processImageVO(imagelist,environmentvo); //处理上传的图片
		} catch (Throwable e) {
			UpLoadFile.deleteFile(imagelist);
			e.printStackTrace();
			throw new UILayerException("file_upload_fail");
		}
		//添加数据到后台
		environmentvo.setProjectId(getObjectFSession().getKeyword());
		environmentvo.setCreator(super.getUserId());  //设置当前操作用户
		setAttribute(environmentvo); //设置操作变量(保存并新增标识、保存标识)
		environmentvo = projectService.addEnvironment(environmentvo);
		getObjectFSession().getEnvironmentVO().add(environmentvo);
		return "projectEnvironmentAdd";
	}

	/**
	 * 功能描述:  修改期数基本资料<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String editBase(@Read ProjectVO projectvo){
		if(projectvo != null){//设置基本信息
			ProjectVO cacheProjectVO = getObjectFSession();
			projectvo.setKeyword(cacheProjectVO.getKeyword());
			projectvo.setProjectCreator(cacheProjectVO.getProjectCreator());
			projectvo.setProjectModifier(cacheProjectVO.getProjectModifier());
		}
		ProjectVO editedProjectvo = projectService.editBase(projectvo);
		setObject2Session(editedProjectvo);
		setAttribute();
		return "projectBaseInfo";
	}

	/**
	 * 功能描述:  修改配套设施.先处理上传的图片，再在后台修改，再同步更新session中的数据 <br>
	 * @param environmentvo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String editEnvironment(){
		UpLoadFile upload=new UpLoadFile();
		EnvironmentVO environmentvo = new EnvironmentVO();
		List<ImageVO> imagelist = null;
		try {
			//获取图片列表
			imagelist = upload.parseFormAndUpload(getRequest(), environmentvo);
			processImageVO(upload,imagelist,environmentvo); //处理上传的图片
			ImageVO imagevo = upload.wrapImage("ichnographysImage", environmentvo.getIchnographysImage());
			environmentvo.setIchnographysImage(processImageNull(imagevo));

			imagevo = upload.wrapImage("visionImage", environmentvo.getVisionImage());
			environmentvo.setVisionImage(processImageNull(imagevo));
		} catch (Throwable e) {
			UpLoadFile.deleteFile(imagelist);
			e.printStackTrace();
		}
		checkNull(environmentvo.getKeyword());
		environmentvo.setCreator(super.getUserId());
		environmentvo.setModifier(super.getUserId());

		setAttribute(environmentvo);

		environmentvo = projectService.editEnvironment(environmentvo);

//		先把以前的VO删除，再添加到最后
		getObjectFSession().getEnvironmentVO().remove(environmentvo);
		getObjectFSession().getEnvironmentVO().add(environmentvo);


		return "projectEnvironmentEdit";
	}

	/**
	 * 功能描述:  根据配套设施ID删除配套设施。1:先后台删除。2:从缓存中删除<br>
	 * @param id
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void deleteEnvironmentById(@Read(key="environmentId")Long id){
		//从后台删除VO
		EnvironmentVO environmentVO = getEnvironmentVOFromSession(id);
		environmentVO = projectService.deleteEnvironment(environmentVO);
		//从缓存中删除VO
		if(environmentVO != null)
			getObjectFSession().getEnvironmentVO().remove(environmentVO);
	}

	/**
	 * 功能描述:  添加建设规划<br>
	 * @param layoutvo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String addProjectLayout(@Read LayoutVO layoutvo){
		layoutvo.setProjectId(getObjectFSession().getKeyword());
		LayoutVO layout = projectService.addLayout(layoutvo);
		getObjectFSession().setLayoutVO(layout);
		setAttribute();
		return "projectLayout";
	}

	/**
	 * 功能描述:  编辑配套设施<br>
	 * @param layoutvo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-17  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String editProjectLayout(@Read LayoutVO layoutvo){
		checkNull(layoutvo);
		checkNull(layoutvo.getKeyword());
		LayoutVO layout = projectService.editLayout(layoutvo);
		getObjectFSession().setLayoutVO(layout);
		setAttribute();
		return "projectLayout";
	}
	/**
	* Function:根据期数ID删除期数
	* @param projectId:期数ID
	* @return
	* Create author:yixianjian
	* Create on:2008-7-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public void deleteProjectById(@Read(key="projectId")Long projectId){
		try{
			projectService.deleteProject(projectId);
		}
		catch(Exception ex){
			throw new UILayerException("house:house_not_delete_exception",UILayerException.FAILURE);
		}
	}
	/**
	 * 功能描述:  提供ID，删除参建单位MAP中对应的参建单位<br>
	 * @param coworkid
	 * @param coWorkerType  参建单位类型
	 * Create author:yixianjian <br>
	 * Create on:2008-7-17  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void deleteCoWorkerById(@Read(key="coWorkId")Long coworkid,
									@Read(key="coWorkerType")String coWorkerType){
		checkNull(coWorkerType);
		checkNull(coworkid);
		Map<Long,CoWorkerVO> map = getCoWorkerMapFromProject(coWorkerType);
		map.remove(coworkid);
	}
	/**
	 * 功能描述:  多个COWORKER id组成字符串，通过该IDS从数据库中查询coworkervo添加到projectvo，这个主要在前台操作<br>
	 * @param coworkerIds
	 * Create author:yixianjian <br>
	 * Create on:2008-7-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void addCoWorkerToProjectForSession(@Read(key="coworkerIds")String coworkerIds,
									 @Read(key="coworkType")String coworkType){
		checkNull(coworkerIds);
		checkNull(coworkType);
		CoWorkerVO coWorkervo = getCoWorkerByType(coworkType);
		coWorkervo.setIsIn(true);
		coWorkervo.setCoWorkerIDs(coworkerIds);
		List<CoWorkerVO> list = coWorkerService.queryAllCoWorkerByCoWorkerType(coWorkervo);
		//获取projectvo中对应的map 参建单位VO
		Map<Long,CoWorkerVO> coworkerMap = getCoWorkerMapFromProject(coworkType);
		//将选择的List添加到project对应的map中去
		for(CoWorkerVO item : list){
			coworkerMap.put(item.getCoWorkerID(), item);
		}
		renderText("true");
	}

	/**
	 * 功能描述:  保存选择的参建单位<br>
	 *
	 * Create author:yixianjian <br>
	 * Create on:2008-7-17  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void saveCoWorkerToProject(){
		ProjectVO projectvo = projectService.addJoinCorps(getObjectFSession());
		setObject2Session(projectvo);
	}
	/**
	 * 功能描述:  用户选择了要删除的参建单位,通过ID删除保存在SESSION中的参见单位<br>
	 * @param coWorkerIds
	 * Create author:yixianjian <br>
	 * Create on:2008-7-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void deleteCoWorker(@Read(key="coworkerId")Long coWorkerId){
		System.out.println(coWorkerId);
	}
	/**
	* Function:验证期数的唯一性
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public void validateProjectName(@Read(key="projectId")String projectId,@Read(key="name")String name){
		if(BlankUtil.isBlank(name))
			return;
		Long count = projectService.checkProjectName(name,projectId);
		renderText( count != 0 ? "false":"true");
	}

	/**
	 * 功能描述: 验证配套设施名称唯一性 <br>
	 * @param name
	 * Create author:yixianjian <br>
	 * Create on:2008-7-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validateEnvironmentName(@Read(key="name")String name,
										@Read(key="environmentId")Long environmentId){
		if(BlankUtil.isBlank(name))
			return;
		Long count = projectService.checkEnvironmentName(name,getObjectFSession().getKeyword(),environmentId);
		renderText(count > 0 ?"false":"true");
	}
	/**
	* Function:响应设计的号召,需把期数资料缓存。
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	public void setObject2Session(ProjectVO projectvo){
		setAttribute(PROJECTVO, projectvo,Scope.SESSION);
	}
	/**
	* Function:从session中获取期数资料
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	public ProjectVO getObjectFSession(){
		return (ProjectVO)getAttribute(PROJECTVO,Scope.SESSION);
	}
	/**
	 * 功能描述:  从session中删除缓存projectvo<br>
	 * 在关闭添加、修改窗体前，需要清空
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void removeObjectFSession(){
		removeAttribute(PROJECTVO, Scope.SESSION);
	}
	/**
	 * 功能描述:  主要处理iamge.wrapImage 是不管怎么样都会返回给imageVO<br>
	 * 由于在ImageService判断非空是直接判断对象本身是否为NULL,所以要处理下
	 *
	 * 当iamgevo所有属性都为空时,返回NULL,否则返回imageVO本身
	 * @param imageVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-5  <br>
	 */
	private ImageVO processImageNull(ImageVO imageVO){
		if(imageVO == null) return null;
		if(imageVO.getId() == null &&
				imageVO.getCreator() == null &&
				imageVO.getFieldName() == null &&
				imageVO.getName() == null &&
				imageVO.getPath() == null)
			return null;
		return imageVO;
	}
	/**
	* Function:设置属性，标识是点关闭按钮还是点保存按钮(无图片状态下)
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	private void setAttribute(){
		String isEdit = getRequest().getParameter("isEdit");
		String isSave = getRequest().getParameter("isSave");
		if(BlankUtil.isBlank(isEdit) && !BlankUtil.isBlank(isSave)){
			setAttribute("isSave","isSave");
			removeAttribute("isEdit");
		}else if(!BlankUtil.isBlank(isEdit) && BlankUtil.isBlank(isSave)){
			setAttribute("isEdit","isEdit");
			removeAttribute("isSave");
		}
	}
	/**
	* Function:设置属性，标识是点关闭按钮还是点保存按钮(有图片状态下--配套设施专用)
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	private void setAttribute(EnvironmentVO environmentVO){
		String isReload = environmentVO.getIsReload();
		//设置保存并新增标识
		if("isReload".equals(isReload) && !"isSave".equals(environmentVO.getIsSave())){
			setAttribute("isReload", "isReload");
			removeAttribute("isSave");
		} //设置保存标识
		else if(!"isReload".equals(isReload) && "isSave".equals(environmentVO.getIsSave())){
			setAttribute("isSave", "isSave");
			removeAttribute("isReload");
		}
	}
	/**
	 * 功能描述: 根据ID获取配套设施ID <br>
	 * @param id
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-15  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private EnvironmentVO getEnvironmentVOFromSession(Long id){
		checkNull(id);

		EnvironmentVO environmentVO = null;
		ProjectVO projectvo = getObjectFSession();
		List environmentList = projectvo == null?  null:projectvo.getEnvironmentVO();
		Iterator<EnvironmentVO> iterator = environmentList == null ? null: environmentList.iterator();

		if(iterator == null) return null;

		while(iterator.hasNext()){
			environmentVO = iterator.next();
			if(environmentVO.getKeyword() != null && environmentVO.getKeyword().longValue() == id.longValue()){
				break;
			}

		}
		return environmentVO;
	}
	/**
	 * 功能描述: 处理提交的图片。有效果图、平面图之分 <br>
	 * @param imagelist
	 * @param environmentvo
	 * Create author:yixianjian <br>
	 * Create on:2008-7-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void processImageVO(List<ImageVO> imagelist,EnvironmentVO environmentvo){
		processImageVO(null,imagelist,environmentvo);
	}
	/**
	* Function:处理提交的图片。有效果图、平面图之分。
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-7-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	private void processImageVO(UpLoadFile upload,List<ImageVO> imagelist,EnvironmentVO environmentvo){
		for(ImageVO imagevo : imagelist){
			if(imagevo.getFieldName() == null){
				throw new UILayerException("house:houproject_image_filed_nonull");
			}
			//平面图
			if(imagevo.getFieldName().contains("ichnographysImage")){
				environmentvo.setIchnographysImage(imagevo);
			}
			//效果图
			if(imagevo.getFieldName().contains("visionImage")){
				environmentvo.setVisionImage(imagevo);
			}
			//添加创建人
			imagevo.setCreator(super.getUserId());
		}
	}

	/**
	 * 功能描述:  给定参建类型，获取VO<br>
	 * @param coworkType
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private CoWorkerVO getCoWorkerByType(String coworkType){
		CoWorkerVO queryCondition = new CoWorkerVO();
		if(this.DEVELOPER.equals(coworkType)){
			queryCondition.setCoworkerTypeCode(SysrefcodeDO.WORKER_TYPE);
			queryCondition.setCoworkerTypeValue(SysrefcodeDO.CS_CO_WORKER_TYPE_DEVELOPER);
		}else if(this.DESIGN.equals(coworkType)){
			queryCondition.setCoworkerTypeCode(SysrefcodeDO.WORKER_TYPE);
			queryCondition.setCoworkerTypeValue(SysrefcodeDO.CS_CO_WORKER_TYPE_DESIGN);
		}else if(this.CONSTRUCTION.equals(coworkType)){
			queryCondition.setCoworkerTypeCode(SysrefcodeDO.WORKER_TYPE);
			queryCondition.setCoworkerTypeValue(SysrefcodeDO.CS_CO_WORKER_TYPE_CONSTRUCT);
		}else if(this.SUPERVISION.equals(coworkType)){
			queryCondition.setCoworkerTypeCode(SysrefcodeDO.WORKER_TYPE);
			queryCondition.setCoworkerTypeValue(SysrefcodeDO.CS_CO_WORKER_TYPE_SUPERVISE);
		}
		return queryCondition;
	}

	/**
	 * 功能描述:  获取projectvo中对应的参建单位<br>
	 * @param coworkType
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-7-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Map<Long,CoWorkerVO> getCoWorkerMapFromProject(String coworkType){
		Map<Long,CoWorkerVO> coworkerMap = null;
		if(this.DEVELOPER.equals(coworkType)){
			coworkerMap = getObjectFSession().getDeveloper();
		}else if(this.DESIGN.equals(coworkType)){
			coworkerMap = getObjectFSession().getDesignCorps();
		}else if(this.CONSTRUCTION.equals(coworkType)){
			coworkerMap = getObjectFSession().getBuildCorps();
		}else if(this.SUPERVISION.equals(coworkType)){
			coworkerMap = getObjectFSession().getSurveillants();
		}
		return coworkerMap;
	}

	/**
	 * 功能描述: 查询建设单位,将存在缓存中的建设单位ID查询出来<br>
	 * @param coworkType
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-11-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String getCoWorkerIdsFromSession(String coworkType){
		StringBuffer ids = new StringBuffer();
		Map<Long,CoWorkerVO> coworkerMap = getCoWorkerMapFromProject(coworkType);
		Iterator<Long> iterator  = coworkerMap.keySet().iterator();
		if(iterator.hasNext())
			ids.append(String.valueOf(iterator.next()));
		while(iterator.hasNext()){
			ids.append(",").append(String.valueOf(iterator.next()));
		}
		return ids.toString();
	}
	/**
	 * 功能描述:  检查空指针异常<br>
	 * @param obj
	 * Create author:yixianjian <br>
	 * Create on:2008-7-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void checkNull(Object obj){
		if(obj == null)
			throw new UILayerException("param cann't null");
	}
	public void setProjectService(IProjectService projectService) {
		this.projectService = projectService;
	}
	public void setCoWorkerService(ICoWorkerService coWorkerService) {
		this.coWorkerService = coWorkerService;
	}
}
